import CryptoJS from 'crypto-js'

const TokenKey = 'App-Token'
const TokenKeyAlias = 'Token-Alias'

export function getToken() {
  return uni.getStorageSync(TokenKey)
}

export function setToken(token) {
  return uni.setStorageSync(TokenKey, token)
}

export function removeToken() {
  return uni.removeStorageSync(TokenKey)
}

export function getTokenAlias() {
  return uni.getStorageSync(TokenKeyAlias)
}

export function setTokenAlias(token) {
  return uni.setStorageSync(TokenKeyAlias, token)
}

export function getStatus() {
  return uni.getStorageSync('status')
}

export function setStatus(status) {
  return uni.setStorageSync('status', status)
}


export function AESdecrypt(word, secret) {
  const base = CryptoJS.MD5(secret).toString()
  const secretKey = CryptoJS.enc.Utf8.parse(base)
  return CryptoJS.enc.Utf8.stringify(
    CryptoJS.AES.decrypt(word, secretKey, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
  ).toString()
}

export function AESencrypt(word, secret) {
  const base = CryptoJS.MD5(secret).toString()
  const secretKey = CryptoJS.enc.Utf8.parse(base)
  const srcs = CryptoJS.enc.Utf8.parse(word)
  return CryptoJS.AES.encrypt(srcs, secretKey, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString()
}